<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>
<%@ taglib prefix="s" uri="/struts-tags"%>
<%@ page language="java" import="java.sql.* " %>
<%@page import="lookups.entity.Address"%>
<%@page import="lookups.dao.AddressDAO"%>
<%@page import="java.util.ArrayList"%>

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Address Lookup</title>
<link rel="stylesheet" type="text/css" href="css_tuan.css">
<!--  <link href="templatemo_style.css" rel="stylesheet" type="text/css" />-->
	
</script><script type="text/javascript">

     function getselect(){
		    var radios = document.getElementsByName("a");
			
		    for (var i = 0; i < radios.length; i++) {       
		        if (radios[i].checked) {
		            return radios[i].value;
		        }
		    }	   
	}
     function returnvalue(){
    	 selectval=getselect();
    	// alert(selectval);
    
    	 addressname=document.getElementById(selectval).options[0].value;
    	 postcode=document.getElementById(selectval).options[1].value;
    	 townname=document.getElementById(selectval).options[2].value;
    	 countyname=document.getElementById(selectval).options[3].value;
    	 countryname=document.getElementById(selectval).options[4].value;
    	 
    	 //alert(addressname);
    	 
    	 window.opener.lookup.addr1.value=addressname;
    	 window.opener.lookup.addr2.value=addressname;
    	 window.opener.lookup.addr3.value=addressname;
    	 window.opener.lookup.postcode.value=postcode;
    	 window.opener.lookup.town.value=townname;
    	 window.opener.lookup.county.value=countyname;
    	 window.opener.lookup.country.value=countryname;
    	 
    	 self.close();
     }
     function returnnone(){
    	 window.opener.lookup.addr1.value='';
    	 window.opener.lookup.addr2.value='';
    	 window.opener.lookup.addr3.value='';
    	 window.opener.lookup.postcode.value='';
    	 window.opener.lookup.town.value='';
    	 window.opener.lookup.county.value='';
    	 window.opener.lookup.country.value='';
    	 self.close();
     }
     function loadonopen() {
		document.load.submit();
	 }
     window.onload=function hide(){
    	 var selecttag = document.getElementsByTagName('select');
    	 for(var i=0;i<selecttag.length;i++){
    		 selecttag[i].style.visibility = 'hidden';
    	 }
    	 
     }
     
</script>
</head>
<body >

<div class="body">
	<div class="top"><b>Search Postcode</b></div>
	<form action="addresslookup" method="post" name="load" >
	
		<div class="div_color" align="center">
			Postcode:&nbsp;&nbsp;&nbsp;<input type="text" name="postcode"  id="postcode" size="15">
			Street:&nbsp;&nbsp;&nbsp;<input type="text" name="street"  id="street" size="15">
			Town:&nbsp;&nbsp;&nbsp;<input type="text" name="town" id="town" size="15">
		</div>
		<div class="margin">
			<input type="submit" name="searchaddress" value="Search Address" >
			<input type="button" name="none" value="None" onclick="returnnone()">
			<input type="button" name="clear" value="Clear" onclick="document.getElementById('postcode').value='';document.getElementById('street').value='';document.getElementById('town').value='';">
		</div>
	
		<table border="1">
		<tr class="tr">
		<th class="th">&nbsp;&nbsp;&nbsp;</th>
		<th class="th">Address</th>
		<th class="th">Post code</th>
		<th class="th">Town</th>
		<th class="th">County</th>
		<th class="th">Country</th>
		</tr>
		<s:iterator value="listaddress" status="status">
		 <s:if test="#status.odd == true">
     		 <tr class="tr">
    	</s:if>
    	<s:else>
      		<tr class="tr_dark">
    	</s:else>
    	
		<td><input type="radio" id="a" name="a" value='<s:property value="addressID" />'></td>
		<td>
			<s:property value="addressName"/>
			<select id='<s:property value="addressID" />' >
				<option value='<s:property value="addressName"/>'></option>
  				<option value='<s:property value="postCode"/>'></option>
  				<option value='<s:property value="town.townName"/>'></option>
  				<option value='<s:property value="county.countyName"/>'></option>
  				<option value='<s:property value="country.countryName"/>'></option>
			</select>	
		</td>
		<td><s:property value="postCode"/></td>
		<td><s:property value="town.townName"/></td>
		<td><s:property value="county.countyName"/></td>
		<td><s:property value="country.countryName"/></td>
		</tr>
		</s:iterator>
		
		</table> 
		
		<div class="paging" >
			<s:submit type="image" src="ic_prev.png"  width="16px" height="16px" action="previouspageaaction"/>
				<input type="text" name="pageNum" value='<s:property value="pageNum"/>' size="1">/<b><s:property value="totalPage" /></b><input type="submit" name="Go" value="Go" size="1"  />
			<s:submit type="image" src="ic_next.png"  width="16px" height="16px" action="nextpageaaction"/>
		</div>
		
		<br>
		<input type="button" name="select" value="Select" onclick="returnvalue()"/>
		<input type="button" name="close" value="Close" onclick="window.close()">
		
		
	</form>
</div>
</body>
</html>